﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace CPPEI.Coolzon.Designer.Views
{
    [ValueConversion(typeof(NodeStatus), typeof(string))]
    public class NodeStatusToString : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string ret;
            NodeStatus nodeStatus = (NodeStatus)value;
            switch (nodeStatus)
            {
                case NodeStatus.Add:
                    ret = "新增";
                    break;
                case NodeStatus.CheckIn:
                    ret = "签入";
                    break;
                case NodeStatus.CheckOut:
                    ret = "签出";
                    break;
                case NodeStatus.OthersLocked:
                    ret = "被占用";
                    break;
                case NodeStatus.Delete:
                    ret = "删除";
                    break;
                case NodeStatus.NotInSourceControl:
                default:
                    ret = "";
                    break;
            }

            return ret;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            NodeStatus nodeStatus = default(NodeStatus);
            string str = System.Convert.ToString(value);
            if (string.IsNullOrWhiteSpace(str))
            {
                return nodeStatus;
            }
            if (string.Equals(str, "新增"))
            {
                nodeStatus = NodeStatus.Add;
            }
            else if (string.Equals(str, "签入"))
            {
                nodeStatus = NodeStatus.CheckIn;
            }
            else if (string.Equals(str, "签出"))
            {
                nodeStatus = NodeStatus.CheckOut;
            }
            else if (string.Equals(str, "被占用"))
            {
                nodeStatus = NodeStatus.OthersLocked;
            }
            else if (string.Equals(str, "删除"))
            {
                nodeStatus = NodeStatus.Delete;
            }
            else
            {
                nodeStatus = NodeStatus.NotInSourceControl;
            }
            return nodeStatus;
        }
    }
}
